// 封装倒计时组合式API模块

import { useIntervalFn } from '@vueuse/core'
import { ref } from 'vue'

export const useCountDown = (init = 60) => {
  const count = ref(init)
  const { pause, resume } = useIntervalFn(() => {
    count.value--
    if (count.value <= 0) {
      // 已经减到头了，暂停并恢复初始值
      // 暂停
      pause()
    }
  }, 10000)
  // 重新开始
  const start = () => {
    count.value = init
    resume()
  }
  return {
    count,
    start
  }
}
